/**
 * Copyright 2008 Benjamin Possolo
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.javenue.util.process;

import java.lang.annotation.ElementType;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.annotation.Retention;

/**
 * An annotation that can be applied to the <code>doTransition()</code> method of a 
 * <tt>Transition</tt> or <tt>TransitionWithResult</tt>
 * type to indicate that the method is idempotent.
 * <p>
 * An idempotent transition is automatically reattempted by the underlying
 * <tt>Process</tt>/<tt>TransitionManager</tt> system when the transition fails.
 * <p>
 * This annotation offers several attributes that can be specified to alter the idempotent behaviour;
 * namely, the maximum number of retry attempts, the amount of time to wait between attempts,
 * and the exception types that, when thrown, should cause the transition to be reattempted.
 *  
 * @author Benjamin Possolo
 * <p>Created on Jul 20, 2008
 */
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Idempotent {
	
	/**
	 * Represents the maximum number of times that an idempotent transition will be attempted.
	 * Default value is 3 attempts.
	 */
	int attempts() default 3;
	
	/**
	 * Represents the amount of time to wait between attempts.
	 * Value should be a number followed by 's', 'm' or 'h'
	 * for seconds, minutes or hours respectively.
	 * Default value is <code>"5m"</code> (5 minutes).
	 */
	String delay() default "5m";
	
	/**
	 * Represents the exceptions that can cause a transition to be retried.
	 * The class objects should represent runtime exceptions (i.e. any class that
	 * is either a RuntimeException or an Error). Default value is an empty array
	 * which means all runtime exceptions cause the idempotent transition to be retried.
	 */
	Class<?>[] ex() default {};
}
